@echo off
setlocal
rem 示例用法：package.cmd linux
rem 示例用法：package.cmd windows
rem 示例用法：package.cmd linux arm64
rem 检查参数数量
chcp 65001 > nul
if "%~1"=="" (
    echo 用法: package.cmd <平台> [架构]
    exit /b 1
)
set PLATFORM=%1
set ARCH=%2

rem 设置默认架构为amd64，如果未指定架构参数的话
if "%ARCH%"=="" set ARCH=amd64

rem 创建输出文件夹（如果不存在）
if not exist out mkdir out

rem 根据平台和架构生成可执行文件
if "%PLATFORM%"=="linux" (
    set CGO_ENABLED=0
    set GOOS=linux
    if "%ARCH%"=="amd64" (
        set GOARCH=amd64
    ) else if "%ARCH%"=="arm64" (
        set GOARCH=arm64
    ) else (
        echo 不支持的架构：%ARCH%
        exit /b 1
    )
    go build -o out/app_linux_%ARCH% main.go
) else if "%PLATFORM%"=="windows" (
    set CGO_ENABLED=1
    set GOOS=windows
    if "%ARCH%"=="amd64" (
        set GOARCH=amd64
    ) else (
        echo 不支持的架构：%ARCH%
        exit /b 1
    )
    go build -o out/app_windows_%ARCH%.exe main.go
) else (
    echo 不支持的平台：%PLATFORM%
    exit /b 1
)

echo 打包完成：%PLATFORM% %ARCH%
